var jsVersion = 180925;
var KgUser = KgUser || {
    $: function() {
        var els = [];
        for (var i = 0, l = arguments.length; i < l; i++) {
            var el = arguments[i];
            if (typeof el == "string")
                el = document.getElementById(el);
            if (l == 1)
                return el;
            els.push(el);
        }
        return els;
    },
    $T: function(tagName, el) {
        var els = (this.$(el) || document).getElementsByTagName(tagName || "*");
        return this.$A(els);
    },
    $A: function(args) {
        var arr = [];
        for (var i = 0, l = args.length; i < l; i++) {
            arr.push(args[i]);
        }
        return arr;
    },
    $C: function(name, el, tagName) {
        var cEls = []
          , i = 0;
        if (!!document.getElementsByClassName) {
            var arr = this.$(el || document).getElementsByClassName(name);
            arr = this.$A(arr);
            if (tagName && tagName !== "*") {
                for (var l = arr.length; i < l; i++) {
                    (arr[i].tagName.toLowerCase() === tagName.toLowerCase()) && cEls.push(arr[i]);
                }
            } else {
                cEls = arr;
            }
        } else {
            for (var arr = this.$T(tagName, el), l = arr.length; i < l; i++) {
                new RegExp("\\b" + name + "\\b","g").test(arr[i].className) && cEls.push(arr[i]);
            }
        }
        return cEls;
    },
    addJsVersion: function(url) {
        if (url.indexOf('?') == -1) {
            return url + "?kguser_jv=" + jsVersion;
        } else {
            return url + "&kguser_jv=" + jsVersion;
        }
    },
    isAckHost: function(url, lhost) {
        var urlArr = url.split("/");
        if (urlArr.length <= 2) {
            return true;
        }
        return urlArr[2] != lhost;
    },
    loadScriptN: function(url, args, callback, async) {
        var is_timeout = false;
        var timeoutid = null;
        var timeout = 3000;
        var params = args || "";
        if (args && (typeof args === "object")) {
            if (KgUser.IsEmpty(args.mid)) {
                args["mid"] = KgUser.Cookie.read(KgUser.KgMid.name);
            }
            var str = "";
            for (var i in args) {
                if (i === 'error')
                    continue;
                str += i + "=" + args[i] + "&";
            }
            params = str.substr(0, str.length - 1);
            if (!KgUser.IsEmpty(args.timeout)) {
                timeout = args.timeout;
            }
        }
        ;var script = document.createElement("script");
        script.type = 'text/javascript';
        if (params != null && params != "") {
            url = url + "?" + (params || '');
        }
        url = KgUser.addJsVersion(url);
        var err_type = KgUser.KgErrType.busislave;
        if (url.indexOf("KgAck") > -1) {
            err_type = KgUser.KgErrType.ackjs;
        }
        script.src = url;
        script.onload = script.onreadystatechange = function() {
            if (!this.readyState || (this.readyState == "complete" || this.readyState == "loaded")) {
                script.onreadystatechange = script.onload = null;
                script = null;
                clearTimeout(timeoutid);
                callback && callback();
            }
        }
        ;
        script.onerror = function() {
            if (!is_timeout) {
                clearTimeout(timeoutid);
                args.error && args.error(err_type);
            }
        }
        ;
        if (async)
            script.async = 'async';
        timeoutid = setTimeout(function() {
            is_timeout = true;
            args.error && args.error(err_type);
        }, timeout);
        document.getElementsByTagName("head")[0].appendChild(script);
    },
    loadScript: function(url, args, callback) {
        var is_timeout = false;
        var timeoutid = null;
        var timeout = 3500;
        var oArgs = args;
        var oUrl = url;
        var params = args || "";
        if (args && (typeof args === "object")) {
            if (KgUser.IsEmpty(args.mid)) {
                args["mid"] = KgUser.Cookie.read(KgUser.KgMid.name);
            }
            var str = "";
            for (var i in args) {
                if (i === 'error')
                    continue;
                str += i + "=" + args[i] + "&";
            }
            params = str.substr(0, str.length - 1);
            if (KgUser.IsEmpty(args.timeout)) {
                oArgs.timeout = timeout;
            }
        }
        ;var script = document.createElement("script");
        script.type = 'text/javascript';
        if (params != null && params != "") {
            url = url + "?" + (params || '');
        }
        url = KgUser.addJsVersion(url);
        KgUser.KgUrl.verify = "http://verifycode.service.kugou.com/";
        var urlArr = url.split("/");
        if (urlArr.length <= 2) {
            args.error && args.error(KgUser.KgErrType.param);
            return;
        }
        var host = urlArr[2];
        var need_retry = (host == "login-user.kugou.com" || host == "reg-user.kugou.com");
        var err_type = KgUser.KgErrType.busislave;
        if (need_retry) {
            err_type = KgUser.KgErrType.busimaster;
        } else if (url.indexOf("KgAck") > -1) {
            err_type = KgUser.KgErrType.ackjs;
        }
        script.src = url;
        var isok = false;
        script.onload = script.onreadystatechange = function() {
            if (!this.readyState || (this.readyState == "complete" || this.readyState == "loaded")) {
                script.onreadystatechange = script.onload = null;
                script = null;
                isok = true;
                clearTimeout(timeoutid);
                callback && callback();
            }
        }
        ;
        script.onerror = function() {
            if (need_retry) {
                if (!is_timeout) {
                    clearTimeout(timeoutid);
                    KgUser.ackRetry(oUrl, host, oArgs, callback);
                }
            } else {
                args.error && args.error(err_type);
            }
        }
        ;
        document.getElementsByTagName("head")[0].appendChild(script);
        if (need_retry) {
            timeoutid = setTimeout(function() {
                if (!isok) {
                    is_timeout = true;
                    KgUser.ackRetry(oUrl, host, oArgs, callback);
                }
            }, timeout);
        }
    },
    KgAckId: {
        login: 10015,
        reg: 10016,
        verify: 10017,
        url: "http://serveraddr.serviceweb.kugou.com/KgAck.js",
        url_https: "https://serveraddrweb.kugou.com/KgAckV2.js"
    },
    ackCallBack: function(dataObj) {
        if (dataObj.errorCode == 1) {
            var g_param = KgUser.KgAckId.global_param;
            var res_data = dataObj.data;
            var loginHost = g_param.loginHost;
            var loginAckHost = res_data["server_" + KgUser.KgAckId.login];
            if (!KgUser.IsEmpty(loginAckHost)) {
                var loginAckHost = loginAckHost["list"][0];
                if (!KgUser.isAckHost(KgUser.KgUrl.login, loginHost)) {
                    KgUser.KgUrl.verify = "http://" + loginAckHost;
                    KgUser.KgUrl.login = KgUser.KgUrl.login.replace(loginHost, loginAckHost);
                    KgUser.KgUrl.loginHTTP = KgUser.KgUrl.loginHTTP.replace(loginHost, loginAckHost);
                }
                KgUser.loadScriptN(g_param.url.replace(loginHost, loginAckHost), g_param.args, g_param.callback);
            }
        } else {}
    },
    ackCallBackUpdateCookie: function(dataObj) {
        setTimeout(function() {
            var ackKey = "ACK_SERVER_" + KgUser.KgAckId.login;
            var ackVal = KgUser.Cookie.read(ackKey);
            if (!KgUser.IsEmpty(ackVal)) {
                KgUser.Cookie.write(ackKey, ackVal, 3600, '/');
            }
        }, 500);
    },
    KgErrType: {
        busimaster: 1,
        busislave: 2,
        ackjs: 3,
        ackconf: 4
    },
    loadAckJs: function(args) {
        var server_list = [KgUser.KgAckId.login, KgUser.KgAckId.reg, KgUser.KgAckId.verify];
        var update_server_list = new Array();
        var ack_cookie_prefix = "ACK_SERVER_";
        for (var i = 0; i < server_list.length; i++) {
            var ack_cookie_name = ack_cookie_prefix + server_list[i];
            var ack_cookie_val = KgUser.Cookie.read(ack_cookie_name);
            if (KgUser.IsEmpty(ack_cookie_val)) {
                update_server_list.push(server_list[i]);
            }
        }
        var appid = 88;
        if (args && args["appid"]) {
            if (parseInt(args["appid"]) > 0) {
                appid = args["appid"];
            }
        }
        window.getAckConfCallback = function() {
            if (typeof KgAck != "undefined") {
                var infoObj = new Object();
                infoObj.appid = appid;
                infoObj.clientver = 10;
                infoObj.clienttime = new Date().getTime();
                infoObj.plats = update_server_list;
                if (typeof args != "undefined") {
                    KgAck.getConfig(infoObj, "KgUser.ackCallBack");
                    if (args.error) {
                        setTimeout(function() {
                            if (KgUser.IsEmpty(KgUser.Cookie.read(ack_cookie_prefix + KgUser.KgAckId.login))) {
                                args.error(KgUser.KgErrType.ackconf);
                            }
                        }, timeout);
                    }
                } else {
                    KgAck.getConfig(infoObj, "KgUser.ackCallBackUpdateCookie");
                }
            }
        }
        ;
        if (update_server_list.length > 0) {
            if (typeof KgAck == "undefined") {
                var ackUrl = KgUser.KgAckId.url;
                if (document.location.protocol == "https:") {
                    ackUrl = KgUser.KgAckId.url_https;
                }
                var param = new Object();
                param.timeout = 3000;
                if (args && args["timeout"]) {
                    param.timeout = args["timeout"];
                }
                if (args && args["error"]) {
                    param.error = args["error"];
                }
                KgUser.loadScriptN(ackUrl, param, getAckConfCallback, true);
            } else {
                getAckConfCallback();
            }
        }
    },
    ackRetry: function(url, host, args, callback) {
        var ack_cookie_prefix = "ACK_SERVER_";
        var regHost = "reg-user.kugou.com";
        var loginHost = "login-user.kugou.com";
        var loginAckHost = KgUser.Cookie.read(ack_cookie_prefix + KgUser.KgAckId.login);
        if (!KgUser.IsEmpty(loginAckHost)) {
            var loginAckHost = KgUser.JSON.parse(loginAckHost)["list"][0];
            if (!KgUser.isAckHost(KgUser.KgUrl.login, loginHost)) {
                KgUser.KgUrl.verify = "http://" + loginAckHost;
                KgUser.KgUrl.login = KgUser.KgUrl.login.replace(loginHost, loginAckHost);
                KgUser.KgUrl.loginHTTP = KgUser.KgUrl.loginHTTP.replace(loginHost, loginAckHost);
            }
            KgUser.loadScriptN(url.replace(host, loginAckHost), args, callback);
            return;
        }
        var tem_obj = new Object();
        tem_obj.loginHost = loginHost;
        tem_obj.url = url;
        tem_obj.args = args;
        tem_obj.callback = callback;
        KgUser.KgAckId.global_param = tem_obj;
        this.loadAckJs(args);
    },
    KgMid: {
        name: "kg_mid",
        days: 10000
    },
    JSON: function() {
        function f(n) {
            return n < 10 ? '0' + n : n;
        }
        Date.prototype.toJSON = function() {
            return this.getUTCFullYear() + '-' + f(this.getUTCMonth() + 1) + '-' + f(this.getUTCDate()) + 'T' + f(this.getUTCHours()) + ':' + f(this.getUTCMinutes()) + ':' + f(this.getUTCSeconds()) + 'Z';
        }
        ;
        var m = {
            '\b': '\\b',
            '\t': '\\t',
            '\n': '\\n',
            '\f': '\\f',
            '\r': '\\r',
            '"': '\\"',
            '\\': '\\\\'
        };
        function stringify(value, whitelist) {
            var a, i, k, l, r = /["\\\x00-\x1f\x7f-\x9f]/g, v;
            switch (typeof value) {
            case 'string':
                return r.test(value) ? '"' + value.replace(r, function(a) {
                    var c = m[a];
                    if (c) {
                        return c;
                    }
                    c = a.charCodeAt();
                    return '\\u00' + Math.floor(c / 16).toString(16) + (c % 16).toString(16);
                }) + '"' : '"' + value + '"';
            case 'number':
                return isFinite(value) ? String(value) : 'null';
            case 'boolean':
            case 'null':
                return String(value);
            case 'object':
                if (!value) {
                    return 'null';
                }
                if (typeof value.toJSON === 'function') {
                    return stringify(value.toJSON());
                }
                a = [];
                if (typeof value.length === 'number' && !(value.propertyIsEnumerable('length'))) {
                    l = value.length;
                    for (i = 0; i < l; i += 1) {
                        a.push(stringify(value[i], whitelist) || 'null');
                    }
                    return '[' + a.join(',') + ']';
                }
                if (whitelist) {
                    l = whitelist.length;
                    for (i = 0; i < l; i += 1) {
                        k = whitelist[i];
                        if (typeof k === 'string') {
                            v = stringify(value[k], whitelist);
                            if (v) {
                                a.push(stringify(k) + ':' + v);
                            }
                        }
                    }
                } else {
                    for (k in value) {
                        if (typeof k === 'string') {
                            v = stringify(value[k], whitelist);
                            if (v) {
                                a.push(stringify(k) + ':' + v);
                            }
                        }
                    }
                }
                return '{' + a.join(',') + '}';
            }
        }
        return {
            stringify: stringify,
            parse: function(text, filter) {
                var j;
                function walk(k, v) {
                    var i, n;
                    if (v && typeof v === 'object') {
                        for (i in v) {
                            if (Object.prototype.hasOwnProperty.apply(v, [i])) {
                                n = walk(i, v[i]);
                                if (n !== undefined) {
                                    v[i] = n;
                                } else {
                                    delete v[i];
                                }
                            }
                        }
                    }
                    return filter(k, v);
                }
                if (/^[\],:{}\s]*$/.test(text.replace(/\\["\\\/bfnrtu]/g, '@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
                    j = eval('(' + text + ')');
                    return typeof filter === 'function' ? walk('', j) : j;
                }
                throw new SyntaxError('parseJSON');
            }
        };
    }(),
    Cookie: {
        write: function(name, value, exp, path, domain, secure) {
            var expires = "";
            if (exp) {
                var dt = new Date();
                dt.setTime(dt.getTime() + (exp * 1000));
                expires = ";expires=" + dt.toGMTString();
            }
            value = encodeURIComponent(value);
            path = path ? '; path=' + (path) : ';path=/';
            domain = domain ? '; domain=' + (domain) : '';
            secure = secure ? '; secure' : '';
            document.cookie = [name, '=', value, expires, path, domain, secure].join('');
        },
        setDay: function(name, value, exp, path, domain, secure) {
            this.write(name, value, (exp * 24 * 60 * 60), path, domain, secure);
        },
        setHour: function(name, value, exp, path, domain, secure) {
            this.write(name, value, (exp * 60 * 60), path, domain, secure);
        },
        setMin: function(name, value, exp, path, domain, secure) {
            this.write(name, value, (exp * 60), path, domain, secure);
        },
        setSec: function(name, value, exp, path, domain, secure) {
            this.write(name, value, (exp), path, domain, secure);
        },
        read: function(name, subName) {
            var cookieValue = "";
            var search = name + "=";
            if (document.cookie.length > 0) {
                offset = document.cookie.indexOf(search);
                if (offset != -1) {
                    offset += search.length;
                    end = document.cookie.indexOf(";", offset);
                    if (end == -1) {
                        end = document.cookie.length;
                    }
                    cookieValue = document.cookie.substring(offset, end);
                    if (typeof subName != 'undefined' && subName != null && subName != "") {
                        var subCookies = cookieValue.toString().split('&');
                        for (var j = 0; j < subCookies.length; j++) {
                            var subCookie = subCookies[j];
                            if (subCookie.substring(0, subName.length + 1) == (subName + '=')) {
                                cookieValue = subCookie.substring(subName.length + 1).replace(/%/g, "\\");
                                break;
                            } else {
                                cookieValue = "";
                            }
                        }
                    }
                }
            }
            return decodeURIComponent(cookieValue);
        },
        remove: function(name) {
            this.write(name, "", -90);
        }
    },
    KgUrl: {
        login: "https://login-user.kugou.com/",
        loginHTTP: "http://login-user.kugou.com/",
        verify: "http://verifycode.service.kugou.com/",
        third: "http://openplat-user.kugou.com/",
        cross: "http://login.user.kugou.com/",
        reg: "https://reg-user.kugou.com/",
        user: "http://userinfo.user.kugou.com/"
    },
    LoadCss: function(cssText, id) {
        var style = document.createElement('style');
        var head = document.head || document.getElementsByTagName('head')[0];
        style.type = 'text/css';
        style.id = id;
        if (style.styleSheet) {
            var func = function() {
                try {
                    style.styleSheet.cssText = cssText;
                } catch (e) {}
            }
            if (style.styleSheet.disabled) {
                setTimeout(func, 10);
            } else {
                func();
            }
        } else {
            var textNode = document.createTextNode(cssText);
            style.appendChild(textNode);
        }
        head.appendChild(style);
    },
    Login: function(infoObj, callbackName) {
        var appid = 0;
        var username = "";
        var pwd = "";
        var code = "";
        var ticket = "";
        var expireday = 1;
        var autologin = false;
        var redirect_uri = '';
        var state = '';
        var mobile = "";
        var mobile_code = "";
        if (KgUser.IsEmpty(infoObj.appid) || KgUser.IsEmpty(KgUser.Trim(infoObj.username)) || KgUser.IsEmpty(KgUser.Trim(infoObj.pwd)) || KgUser.IsEmpty(callbackName)) {
            KgUser.GetMsg(callbackName, {
                errorCode: "20010",
                errorMsg: "必填参数不能为空"
            });
            return false;
        }
        appid = infoObj.appid;
        username = KgUser.Trim(infoObj.username);
        pwd = KgUser.Trim(infoObj.pwd);
        if (!KgUser.IsEmpty(KgUser.Trim(infoObj.code))) {
            code = KgUser.Trim(infoObj.code);
        }
        if (!KgUser.IsEmpty(KgUser.Trim(infoObj.ticket))) {
            ticket = KgUser.Trim(infoObj.ticket);
        }
        if (!KgUser.IsEmpty(infoObj.expire_day)) {
            expireday = infoObj.expire_day;
        }
        if (!KgUser.IsEmpty(infoObj.autologin)) {
            autologin = infoObj.autologin;
        }
        if (!KgUser.IsEmpty(infoObj.redirect_uri)) {
            redirect_uri = infoObj.redirect_uri;
        }
        if (!KgUser.IsEmpty(infoObj.state)) {
            state = infoObj.state;
        }
        if (!KgUser.IsEmpty(KgUser.Trim(infoObj.mobile))) {
            mobile = KgUser.Trim(infoObj.mobile);
        }
        if (!KgUser.IsEmpty(KgUser.Trim(infoObj.mobile_code))) {
            mobile_code = KgUser.Trim(infoObj.mobile_code);
        }
        if (autologin) {
            expireday = 30;
        }
        var param = {
            'appid': appid,
            'username': encodeURIComponent(username),
            'pwd': KgUser.Md5(pwd),
            'code': code,
            'ticket': ticket,
            'clienttime': parseInt(new Date().getTime() / 1000),
            'expire_day': expireday,
            'autologin': autologin,
            'redirect_uri': encodeURIComponent(redirect_uri),
            'state': encodeURIComponent(state),
            'callback': callbackName,
            'error': infoObj.error,
            'login_ver': 1,
            'mobile': mobile,
            'mobile_code': mobile_code
        };
        this.loadScript(KgUser.KgUrl.login + 'v1/login/', param);
    },
    LoginByVerifycode: function(infoObj, callbackName) {
        var appid = 0;
        var mobile = "";
        var code = "";
        var expireday = 1;
        if (KgUser.IsEmpty(infoObj.appid) || KgUser.IsEmpty(KgUser.Trim(infoObj.mobile)) || KgUser.IsEmpty(KgUser.Trim(infoObj.code)) || KgUser.IsEmpty(callbackName)) {
            KgUser.GetMsg(callbackName, {
                errorCode: "20010",
                errorMsg: "必填参数不能为空"
            });
            return false;
        }
        appid = infoObj.appid;
        mobile = KgUser.Trim(infoObj.mobile);
        if (!KgUser.IsEmpty(KgUser.Trim(infoObj.code))) {
            code = KgUser.Trim(infoObj.code);
        }
        if (!KgUser.IsEmpty(infoObj.expire_day)) {
            expireday = infoObj.expire_day;
        }
        var param = {
            'appid': appid,
            'mobile': encodeURIComponent(mobile),
            'code': code,
            'clienttime': parseInt(new Date().getTime() / 1000),
            'expire_day': expireday,
            'callback': callbackName,
            'login_ver': 1
        };
        this.loadScript(KgUser.KgUrl.login + 'v1/loginbyverifycode/', param);
    },
    VerifyCode: function(codeObj, blurCallbackname) {
        var appid = 0;
        var codeid = "";
        var len = 4;
        var width = 90;
        var height = 40;
        var type = "LoginCheckCode";
        var inputid = "";
        var codetype = 0;
        var n = 0;
        if (KgUser.IsEmpty(codeObj.appid)) {
            return false;
        }
        appid = codeObj.appid;
        codeid = KgUser.Trim(codeObj.codeid);
        if (!KgUser.IsEmpty(KgUser.Trim(codeObj.width))) {
            width = KgUser.Trim(codeObj.width);
        }
        if (!KgUser.IsEmpty(KgUser.Trim(codeObj.height))) {
            height = KgUser.Trim(codeObj.height);
        }
        if (!KgUser.IsEmpty(KgUser.Trim(codeObj.type))) {
            type = KgUser.Trim(codeObj.type);
        }
        if (!KgUser.IsEmpty(KgUser.Trim(codeObj.inputid))) {
            inputid = KgUser.Trim(codeObj.inputid);
        }
        var codetype = KgUser.IsEmpty(codeObj.codetype) ? 0 : codeObj.codetype;
        n = Math.round(Math.random() * 100);
        if (type == "RegCheckCode" && typeof codeObj.codetype == 'undefined') {
            if (n >= 0 && n <= 100) {
                codetype = 1;
            } else if (n >= 31 && n <= 40) {
                codetype = 2;
            }
            var ids = inputid.split(',');
            for (i = 0; i < ids.length; i++) {
                if (typeof KgUser.$(ids[i]) != 'undefined') {
                    if (codetype != 0) {
                        KgUser.$(ids[i]).style.display = "none";
                    } else {
                        KgUser.$(ids[i]).style.display = "";
                    }
                }
            }
        }
        KgUser.CodeAll.codetype = codetype;
        KgUser.CodeAll.appid = appid;
        KgUser.CodeAll.codeid = codeid;
        var url = '';
        if (codetype == 3 && type == "LoginCheckCode") {
            url = KgUser.KgUrl.login;
        } else if (type == "LoginCheckCode" || type == "RegCheckCode" || type == "SmsCheckCode") {
            url = KgUser.KgUrl.loginHTTP;
        } else {
            url = KgUser.KgUrl.verify;
        }
        url = url + "v1/get_img_code?type=" + type + "&appid=" + appid + "&codetype=" + codetype + "&t=" + new Date().getTime();
        switch (codetype) {
        case 1:
            setTimeout(function() {
                KgUser.SudokuCode({
                    url: url,
                    id: codeObj.codeid,
                    appid: appid
                }, blurCallbackname);
            }, 100);
            break;
        case 2:
            setTimeout(function() {
                KgUser.ThirdCode({
                    id: codeObj.codeid,
                    url: url
                }, blurCallbackname);
            }, 100);
            break;
        case 3:
            KgUser.SliderVerifyCode({
                url: url,
                appid: appid,
                success: codeObj.success,
                close: codeObj.close,
                update: codeObj.update,
                timeout: codeObj.timeout,
                callback: codeObj.callback,
                callback_deg: codeObj.callback_deg
            });
            break;
        default:
            setTimeout(function() {
                KgUser.$(codeid).style.display = "";
                KgUser.$(codeid).innerHTML = '<img id="KgPopupVerifyCode" src="' + url + '" onclick="KgUser.ChangeVerifyCode(this,' + appid + ',\'' + type + '\')" title="看不清，换一张" alt="看不清，换一张" style="cursor:pointer;width:' + width + 'px;height:' + height + 'px;" />';
            }, 100);
            break;
        }
    },
    ChangeVerifyCode: function(othis, appid, type) {
        setTimeout(function() {
            var url = "";
            if (type == "LoginCheckCode" || type == "RegCheckCode" || type == "SmsCheckCode") {
                url = KgUser.KgUrl.loginHTTP;
            } else {
                url = KgUser.KgUrl.verify;
            }
            othis.src = url + "v1/get_img_code?type=" + type + "&appid=" + appid + "&t=" + new Date().getTime();
        }, 100);
    },
    CheckVerifyCode: function(infoObj) {
        var appid = 0;
        var username = "";
        var t = parseInt((new Date).getTime() / 1000);
        if (KgUser.IsEmpty(infoObj.appid) || KgUser.IsEmpty(KgUser.Trim(infoObj.username))) {
            return false;
        }
        appid = infoObj.appid;
        username = KgUser.Trim(infoObj.username);
        var param = {
            'appid': appid,
            'username': encodeURIComponent(username),
            't': t
        };
        KgUser.loadScript(KgUser.KgUrl.login + "v1/check/", param);
    },
    ThirdLogin: function(infoObj, callbackName) {
        var url = ""
          , name = ""
          , width = 0
          , height = 0
          , partner = "";
        var appid = 0;
        var clienttime = parseInt((new Date).getTime() / 1000);
        var client = "";
        if (!KgUser.IsEmpty(infoObj.appid)) {
            appid = infoObj.appid;
        }
        if (!KgUser.IsEmpty(KgUser.Trim(infoObj.partner))) {
            partner = KgUser.Trim(infoObj.partner).toLowerCase();
        }
        if (!KgUser.IsEmpty(KgUser.Trim(infoObj.client))) {
            client = KgUser.Trim(infoObj.client).toLowerCase();
        }
        var convertPartner = "";
        switch (partner) {
        case "qzone":
            url = KgUser.KgUrl.third + "qq/?";
            name = "TencentLogin";
            width = 470;
            height = 340;
            convertPartner = "qq";
            break;
        case "sina":
            url = KgUser.KgUrl.third + "sina/?";
            name = "SinaLogin";
            width = 562;
            height = 380;
            break;
        case "qqweibo":
            url = KgUser.KgUrl.third + "qqweibo/?";
            name = "QQWeiBoLogin";
            width = 563;
            height = 387;
            break;
        case "renren":
            url = KgUser.KgUrl.third + "renren/?";
            name = "RenrenLogin";
            width = 563;
            height = 387;
            break;
        case "weixin":
            url = KgUser.KgUrl.third + "weixin/index.php?ktype=0";
            name = "WeiXinLogin";
            width = 563;
            height = 593;
            convertPartner = "wechat";
            break;
        case "esurfing":
            url = KgUser.KgUrl.third + "esurfing/?";
            name = "EsurLogin";
            width = 800;
            height = 458;
            break;
        }
        var bind = 0;
        if (!KgUser.IsEmpty(KgUser.Trim(infoObj.bind))) {
            bind = KgUser.Trim(infoObj.bind);
        }
        var ktypeparam = "";
        if (!KgUser.IsEmpty(KgUser.Trim(infoObj.ktype))) {
            ktypeparam = "&ktype=" + infoObj.ktype;
        }
        if (bind == 1 && convertPartner != "") {
            url = "https://openplat-user.kugou.com/bind?userid=0&bind=1&partnername=" + convertPartner + ktypeparam;
        }
        if (url) {
            url += "&appid=" + appid + "&clienttime=" + clienttime + "&callback=" + callbackName + "&domain=" + KgUser.GetDomain();
            var mid = KgUser.Cookie.read(KgUser.KgMid.name);
            if (!KgUser.IsEmpty(mid)) {
                url += "&mid=" + mid;
            }
            var l = (window.screen.width - width) / 2
              , t = (window.screen.height - height) / 2;
            if (client == "mackugou" || client == 'uwp') {
                url += "&client=" + client;
                switch (partner) {
                case "qzone":
                    width = 540;
                    height = 400;
                    break;
                case "sina":
                    width = 768;
                    height = 400;
                    break;
                }
                if (Supercall) {
                    Supercall.setView({
                        type: 'child',
                        window: 'contentWindow',
                        name: 'ThirdLogin',
                        options: {
                            width: width,
                            height: height,
                            url: url,
                            parent: 'login',
                            standButton: ['close']
                        }
                    }, function() {});
                }
            } else {
                window.open(url, name, "width=" + width + ",height=" + height + ",left=" + l + ",top=" + t + ",menubar=0,scrollbars=0,resizable=0,status=0,titlebar=0,toolbar=0,location=1");
            }
        }
    },
    SliderVerifyCode: function(infoObj) {
        var self = this;
        var success = infoObj.success;
        var close = infoObj.close;
        var update = infoObj.update;
        var callback = infoObj.callback;
        var callback_deg = infoObj.callback_deg;
        var timeout = infoObj.timeout;
        var url = infoObj.url;
        var loadSuccess = false;
        if (!self.tcaptchaJsUrl) {
            if (self.loadingTcaptchaJsUrl) {
                return;
            }
            self.loadingTcaptchaJsUrl = true;
            window.kgSliderVerifyCodeHandler = function(res) {
                self.loadingTcaptchaJsUrl = false;
                if (res && res.success == 0 && res.isDegrade == 1) {
                    callback_deg && callback_deg();
                } else if (res && res.success && res.url) {
                    KgUser.loadScript(res.url, '', function() {
                        loadSuccess = true;
                        self.tcaptchaJsUrl = res.url;
                        self.loadingTcaptchaJsUrl = false;
                        window.navigator.userAgent.indexOf('MSIE') >= 1 ? setTimeout(function() {
                            TCaptchaInit();
                        }, 500) : TCaptchaInit();
                    });
                    if (timeout && timeout > 0) {
                        setTimeout(function() {
                            if (!loadSuccess) {
                                callback && callback(false);
                            }
                        }, timeout);
                    }
                } else {
                    self.loadingTcaptchaJsUrl = false;
                    if (typeof (infoObj.retry) == 'undefined') {
                        infoObj.retry = 3;
                    }
                    if (infoObj.retry > 0) {
                        infoObj.retry--;
                        self.SliderVerifyCode(infoObj);
                    }
                }
            }
            ;
            this.loadScript(url + '&callback=kgSliderVerifyCodeHandler');
        } else {
            TCaptchaInit();
        }
        function TCaptchaInit() {
            window.capDestroy();
            var capOption = {
                showHeader: true,
                type: 'popup',
                start: function() {},
                callback: function(retJson) {
                    loadSuccess = true;
                    handleResult(retJson);
                }
            };
            window.capRefresh();
            update && update();
            callback && callback(true);
            window.capInit(document, capOption);
        }
        function handleResult(retJson) {
            if (!loadSuccess) {
                return;
            }
            if (retJson.ticket && retJson.ret == 0) {
                var ticket = retJson.ticket;
                success && success(ticket);
            } else {
                close && close();
            }
        }
    },
    CrossDomainLogin: function(callbackName) {
        var appid = 0;
        var userid = 0;
        var token = "";
        var ct = parseInt((new Date).getTime() / 1000);
        var domain = KgUser.GetDomain();
        if (!KgUser.IsEmpty(KgUser.Cookie.read('KuGoo', 'a_id'))) {
            appid = parseInt(KgUser.Cookie.read('KuGoo', 'a_id'));
        }
        if (!KgUser.IsEmpty(KgUser.Cookie.read('KuGoo', 'KugooID'))) {
            userid = parseInt(KgUser.Cookie.read('KuGoo', 'KugooID'));
        }
        if (!KgUser.IsEmpty(KgUser.Cookie.read('KuGoo', 'ct'))) {
            ct = parseInt(KgUser.Cookie.read('KuGoo', 'ct'));
        }
        if (!KgUser.IsEmpty(KgUser.Trim(KgUser.Cookie.read('KuGoo', 't')))) {
            token = KgUser.Trim(KgUser.Cookie.read('KuGoo', 't'));
        }
        var param = {
            'a_id': appid,
            'userid': userid,
            't': token,
            'ct': ct,
            'callback': '',
            'domain': domain,
            'midname': KgUser.KgMid.name,
            'days': KgUser.KgMid.days
        };
        var url = KgUser.KgUrl.login;
        KgUser.loadScript(url + "v1/cross/", param, function() {
            if (!KgUser.IsEmpty(callbackName)) {
                var uinfo = new Object();
                if (!KgUser.IsEmpty(KgUser.Cookie.read('KuGoo', 'KugooID'))) {
                    uinfo.userid = parseInt(KgUser.Cookie.read('KuGoo', 'KugooID'));
                }
                if (!KgUser.IsEmpty(KgUser.Cookie.read('KuGoo', 'UserName'))) {
                    uinfo.username = eval("'" + KgUser.Trim(KgUser.Cookie.read('KuGoo', 'UserName')) + "'");
                }
                if (!KgUser.IsEmpty(KgUser.Cookie.read('KuGoo', 'NickName'))) {
                    uinfo.nickname = eval("'" + KgUser.Trim(KgUser.Cookie.read('KuGoo', 'NickName')) + "'");
                }
                if (!KgUser.IsEmpty(KgUser.Trim(KgUser.Cookie.read('KuGoo', 't')))) {
                    uinfo.token = KgUser.Trim(KgUser.Cookie.read('KuGoo', 't'));
                }
                if (!KgUser.IsEmpty(KgUser.Trim(KgUser.Cookie.read('KuGoo', 'Pic')))) {
                    uinfo.pic = KgUser.Trim(KgUser.Cookie.read('KuGoo', 'Pic'));
                }
                KgUser.GetMsg(callbackName, uinfo);
            }
        });
    },
    AutoLogin: function(callbackName) {
        var appid = 0;
        var userid = 0;
        var token = "";
        var ct = parseInt((new Date).getTime() / 1000);
        var domain = KgUser.GetDomain();
        if (!KgUser.IsEmpty(KgUser.Cookie.read('KuGoo', 'a_id'))) {
            appid = parseInt(KgUser.Cookie.read('KuGoo', 'a_id'));
        }
        if (!KgUser.IsEmpty(KgUser.Cookie.read('KuGoo', 'KugooID'))) {
            userid = parseInt(KgUser.Cookie.read('KuGoo', 'KugooID'));
        }
        if (!KgUser.IsEmpty(KgUser.Cookie.read('KuGoo', 'ct'))) {
            ct = parseInt(KgUser.Cookie.read('KuGoo', 'ct'));
        }
        if (!KgUser.IsEmpty(KgUser.Trim(KgUser.Cookie.read('KuGoo', 't')))) {
            token = KgUser.Trim(KgUser.Cookie.read('KuGoo', 't'));
        }
        var param = {
            'a_id': appid,
            'userid': userid,
            't': token,
            'ct': ct,
            'callback': '',
            'domain': domain
        };
        var url = KgUser.KgUrl.login;
        if (!KgUser.IsEmpty(token)) {
            KgUser.loadScript(url + "v1/autologin", param);
        }
    },
    LoginOut: function(appid) {
        KgUser.Cookie.setDay('KuGoo', '', -1, '', '.' + KgUser.GetDomain(), '');
        var url = KgUser.KgUrl.cross + 'v2/loginout/?a_id=' + appid + '&ct=' + parseInt((new Date).getTime() / 1000) + '&domain=' + KgUser.GetDomain();
        if (/MSIE (\d+\.\d+);/.test(navigator.userAgent) || /MSIE(\d+\.\d+);/.test(navigator.userAgent)) {
            var referLink = document.createElement('a');
            referLink.href = url;
            document.body.appendChild(referLink);
            referLink.click();
        } else {
            location.href = url;
        }
    },
    GetDomain: function() {
        var s = /\w*\.(com.cn|com|net.cn|net|org.cn|org|gov.cn|gov|cn|mobi|me|info|name|biz|cc|tv|asia|hk|网络|公司|中国).*$/g;
        return document.domain.toString().match(s)[0];
    },
    GetMsg: function(callbackName, dataObj) {
        if (!KgUser.IsEmpty(callbackName)) {
            window[callbackName](dataObj);
        }
    },
    GetSmsCode: function(infoObj, callbackName) {
        var appid = 0;
        var mobile = "";
        if (KgUser.IsEmpty(infoObj.appid) || KgUser.IsEmpty(KgUser.Trim(infoObj.mobile))) {
            KgUser.GetMsg(callbackName, {
                errorCode: "20010",
                errorMsg: "必填参数不能为空"
            });
            return false;
        }
        if (KgUser.IsEmpty(infoObj.type)) {
            infoObj.type = "reg";
        }
        appid = infoObj.appid;
        mobile = KgUser.Trim(infoObj.mobile);
        type = KgUser.Trim(infoObj.type);
        verifycode = infoObj.verifycode
        if (KgUser.IsEmpty(verifycode)) {
            verifycode = "";
        }
        var param = {
            'appid': appid,
            'mobile': encodeURIComponent(mobile),
            'callback': callbackName,
            'v': 1,
            'verifycode': verifycode,
            'ct': parseInt((new Date).getTime() / 1000),
            'type': type
        };
        if (type != "reg") {
            KgUser.loadScript(KgUser.KgUrl.login + 'v1/send_sms/', param);
        } else {
            KgUser.loadScript(KgUser.KgUrl.login + 'v1/send_sms_for_reg', param);
        }
    },
    RegByUserName: function(infoObj, callbackName) {
        var appid = 0;
        var code = "";
        var expire_day = 1;
        var username = "";
        var sex = 1;
        var password = "";
        var nickname = "";
        var security_email = "";
        var id_card = "";
        var truename = "";
        if (KgUser.CodeAll.codetype == 1) {
            infoObj.code = KgUser.CodeAll.cval;
        }
        if (KgUser.IsEmpty(infoObj.appid) || KgUser.IsEmpty(KgUser.Trim(infoObj.username)) || KgUser.IsEmpty(KgUser.Trim(infoObj.password))) {
            KgUser.GetMsg(callbackName, {
                errorCode: "20010",
                errorMsg: "必填参数不能为空"
            });
            return false;
        }
        if (KgUser.IsEmpty(KgUser.Trim(infoObj.code)) && KgUser.CodeAll.codetype != 2) {
            KgUser.GetMsg(callbackName, {
                errorCode: "20010",
                errorMsg: "验证码不能为空"
            });
            return false;
        }
        appid = infoObj.appid;
        username = KgUser.Trim(infoObj.username);
        password = KgUser.Trim(infoObj.password);
        code = KgUser.Trim(infoObj.code);
        if (!KgUser.IsEmpty(infoObj.expire_day)) {
            expire_day = infoObj.expire_day;
        }
        if (typeof infoObj.sex != 'undefined' && infoObj.sex != null) {
            sex = infoObj.sex;
        }
        if (!KgUser.IsEmpty(KgUser.Trim(infoObj.nickname))) {
            nickname = KgUser.Trim(infoObj.nickname);
        } else {
            nickname = username;
        }
        if (!KgUser.IsEmpty(KgUser.Trim(infoObj.security_email))) {
            security_email = KgUser.Trim(infoObj.security_email);
        }
        if (!KgUser.IsEmpty(KgUser.Trim(infoObj.id_card))) {
            id_card = KgUser.Trim(infoObj.id_card);
        }
        if (!KgUser.IsEmpty(KgUser.Trim(infoObj.truename))) {
            truename = KgUser.Trim(infoObj.truename);
        }
        var param = {
            'regtype': 'username',
            'appid': appid,
            'code': encodeURIComponent(code),
            'expire_day': expire_day,
            'v': 1,
            'username': encodeURIComponent(username),
            'sex': sex,
            'password': KgUser.Md5(password),
            'nickname': encodeURIComponent(nickname),
            'security_email': encodeURIComponent(security_email),
            'id_card': encodeURIComponent(id_card),
            'truename': encodeURIComponent(truename),
            'callback': callbackName,
            'codetype': KgUser.CodeAll.codetype
        };
        if (KgUser.CodeAll.codetype == 2 && typeof KgUser.$C('geetest_challenge', '', 'input')[0] != 'undefined') {
            param.geetest_challenge = KgUser.$C('geetest_challenge', KgUser.CodeAll.codeid, 'input')[0].value;
            param.geetest_validate = KgUser.$C('geetest_validate', KgUser.CodeAll.codeid, 'input')[0].value;
            param.geetest_seccode = KgUser.$C('geetest_seccode', KgUser.CodeAll.codeid, 'input')[0].value;
        }
        KgUser.loadScript(KgUser.KgUrl.login + 'v2/reg', param);
    },
    RegByMobile: function(infoObj, callbackName) {
        var appid = 0;
        var code = "";
        var expire_day = 1;
        var mobile = "";
        var sex = 1;
        var password = "";
        var nickname = "";
        var type = "";
        appid = infoObj.appid;
        mobile = KgUser.Trim(infoObj.mobile);
        code = KgUser.Trim(infoObj.code);
        var param = {};
        var mid = typeof infoObj.mid == 'undefined' ? "" : infoObj.mid;
        var type = typeof infoObj.type == 'undefined' ? "" : infoObj.type;
        if (type == "") {
            if (KgUser.IsEmpty(KgUser.Trim(infoObj.password))) {
                KgUser.GetMsg(callbackName, {
                    errorCode: "20010",
                    errorMsg: "必填参数不能为空"
                });
                return false;
            }
            password = KgUser.Trim(infoObj.password);
            if (!KgUser.IsEmpty(infoObj.expire_day)) {
                expire_day = infoObj.expire_day;
            }
            if (typeof infoObj.sex != 'undefined' && infoObj.sex != null) {
                sex = infoObj.sex;
            }
            if (!KgUser.IsEmpty(KgUser.Trim(infoObj.nickname))) {
                nickname = KgUser.Trim(infoObj.nickname);
            } else {
                nickname = mobile;
            }
            param = {
                'regtype': 'mobile',
                'appid': appid,
                'code': encodeURIComponent(code),
                'expire_day': expire_day,
                'mobile': encodeURIComponent(mobile),
                'sex': sex,
                'password': KgUser.Md5(password),
                'nickname': encodeURIComponent(nickname),
                'error': infoObj.error,
                'callback': callbackName,
                'mid': mid
            };
        } else {
            param = {
                'regtype': 'mobile',
                'appid': appid,
                'code': encodeURIComponent(code),
                'mobile': encodeURIComponent(mobile),
                'callback': callbackName,
                'error': infoObj.error,
                'type': type,
                'mid': mid
            };
        }
        KgUser.loadScript(KgUser.KgUrl.login + 'v2/reg', param);
    },
    RegByEmail: function(infoObj, callbackName) {
        var appid = 0;
        var code = "";
        var expire_day = 1;
        var email = "";
        var sex = 1;
        var password = "";
        var nickname = "";
        if (KgUser.CodeAll.codetype == 1) {
            infoObj.code = KgUser.CodeAll.cval;
        }
        if (KgUser.IsEmpty(infoObj.appid) || KgUser.IsEmpty(KgUser.Trim(infoObj.email)) || KgUser.IsEmpty(KgUser.Trim(infoObj.password))) {
            KgUser.GetMsg(callbackName, {
                errorCode: "20010",
                errorMsg: "必填参数不能为空"
            });
            return false;
        }
        if (KgUser.IsEmpty(KgUser.Trim(infoObj.code)) && KgUser.CodeAll.codetype != 2) {
            KgUser.GetMsg(callbackName, {
                errorCode: "20010",
                errorMsg: "验证码不能为空"
            });
            return false;
        }
        appid = infoObj.appid;
        email = KgUser.Trim(infoObj.email);
        password = KgUser.Trim(infoObj.password);
        code = KgUser.Trim(infoObj.code);
        if (!KgUser.IsEmpty(infoObj.expire_day)) {
            expire_day = infoObj.expire_day;
        }
        if (typeof infoObj.sex != 'undefined' && infoObj.sex != null) {
            sex = infoObj.sex;
        }
        if (!KgUser.IsEmpty(KgUser.Trim(infoObj.nickname))) {
            nickname = KgUser.Trim(infoObj.nickname);
        } else {
            nickname = email;
        }
        var param = {
            'regtype': 'email',
            'appid': appid,
            'code': encodeURIComponent(code),
            'expire_day': expire_day,
            'email': encodeURIComponent(email),
            'sex': sex,
            'password': KgUser.Md5(password),
            'nickname': encodeURIComponent(nickname),
            'callback': callbackName,
            'codetype': KgUser.CodeAll.codetype
        };
        if (KgUser.CodeAll.codetype == 2 && typeof KgUser.$C('geetest_challenge', '', 'input')[0] != 'undefined') {
            param.geetest_challenge = KgUser.$C('geetest_challenge', KgUser.CodeAll.codeid, 'input')[0].value;
            param.geetest_validate = KgUser.$C('geetest_validate', KgUser.CodeAll.codeid, 'input')[0].value;
            param.geetest_seccode = KgUser.$C('geetest_seccode', KgUser.CodeAll.codeid, 'input')[0].value;
        }
        KgUser.loadScript(KgUser.KgUrl.login + 'v2/reg/', param);
    },
    CheckPwd: function(infoObj, callbackName) {
        var appid = 0;
        var password = "";
        var username = "";
        if (KgUser.IsEmpty(infoObj.appid) || KgUser.IsEmpty(KgUser.Trim(infoObj.password))) {
            KgUser.GetMsg(callbackName, {
                errorCode: "20010",
                errorMsg: "必填参数不能为空"
            });
            return false;
        }
        appid = infoObj.appid;
        password = KgUser.Trim(infoObj.password);
        if (!KgUser.IsEmpty(KgUser.Trim(infoObj.username))) {
            username = KgUser.Trim(infoObj.username);
        }
        var param = {
            'appid': appid,
            'str': KgUser.Md5(password),
            'username': encodeURIComponent(username),
            'callback': callbackName
        };
        KgUser.loadScript(KgUser.KgUrl.user + 'check_str/', param);
    },
    CheckReg: function(infoObj, callbackName) {
        var appid = 0;
        var type = 0;
        var username = "";
        if (KgUser.IsEmpty(infoObj.appid) || KgUser.IsEmpty(infoObj.type) || KgUser.IsEmpty(KgUser.Trim(infoObj.username))) {
            KgUser.GetMsg(callbackName, {
                errorCode: "20010",
                errorMsg: "必填参数不能为空"
            });
            return false;
        }
        appid = infoObj.appid;
        type = infoObj.type;
        username = infoObj.username;
        var param = {
            'appid': appid,
            'type': type,
            'username': encodeURIComponent(username),
            'callback': callbackName
        };
        KgUser.loadScript(KgUser.KgUrl.login + 'v2/check_for_reg', param);
    },
    ThirdCode: function(infoObj, callbackName) {
        if (!KgUser.IsEmpty(KgUser.Trim(infoObj.url)) && !KgUser.IsEmpty(KgUser.Trim(infoObj.id))) {
            var url = infoObj.url;
            var id = infoObj.id;
            window.gt_thirdcode = (function(window, document) {
                var head = document.getElementsByTagName('head')[0];
                return function(config, callback) {
                    config.protocol = config.https ? 'https://' : 'http://';
                    var initGeetest = function() {
                        callback(new window.Geetest(config));
                    };
                    var backendDown = function() {
                        var s = document.createElement('script');
                        s.id = 'gt_lib';
                        s.src = config.protocol + 'static.geetest.com/static/js/geetest.0.0.0.js';
                        s.charset = 'UTF-8';
                        s.type = 'text/javascript';
                        head.appendChild(s);
                        var loaded = false;
                        s.onload = s.onreadystatechange = function() {
                            if (!loaded && (!this.readyState || this.readyState === 'loaded' || this.readyState === 'complete')) {
                                initGeetest();
                                loaded = true;
                            }
                        }
                        ;
                    };
                    window.geetest_callback = function() {
                        initGeetest();
                    }
                    ;
                    if (config) {
                        if (config.offline) {
                            backendDown();
                        } else if (!window.Geetest) {
                            var s = document.createElement('script');
                            s.onerror = function() {
                                config.offline = true;
                                backendDown();
                            }
                            ;
                            s.src = config.protocol + 'api.geetest.com/get.php?callback=geetest_callback';
                            head.appendChild(s);
                        } else {
                            initGeetest();
                        }
                    }
                }
            }(window, document));
            if (!KgUser.IsEmpty(KgUser.Trim(id))) {
                KgUser.loadScript(url, "");
                window.gt_succCallback = function(captcha_obj) {
                    if (typeof KgUser.$(id) != 'undefined') {
                        KgUser.$(id).innerHTML = '';
                    }
                    captcha_obj.appendTo("#" + id);
                    captcha_obj.onSuccess(callbackName);
                }
                ;
            }
        }
    },
    CodeAll: {
        kg_sudoku_anslist: ["", "", "", ""],
        kg_sudoku_flag: 0,
        codetype: 0,
        cval: "",
        appid: 0,
        codeid: ""
    },
    SudokuCode: function(infoObj, callbackName) {
        if (!KgUser.IsEmpty(KgUser.Trim(infoObj.url)) && !KgUser.IsEmpty(KgUser.Trim(infoObj.id))) {
            KgUser.CodeAll.cval = "";
            KgUser.CodeAll.kg_sudoku_anslist = ["", "", "", ""];
            KgUser.CodeAll.kg_sudoku_flag = 0;
            var link = document.createElement('link');
            var head = document.head || document.getElementsByTagName('head')[0];
            link.type = 'text/css';
            link.rel = 'stylesheet';
            link.href = KgUser.KgUrl.verify + 'v1/static/css/sudoku.css';
            link.id = 'kg_sudoku_css';
            if (typeof document.getElementById('kg_sudoku_css') == 'undefined' || document.getElementById('kg_sudoku_css') == null) {
                head.appendChild(link);
            }
            var url = infoObj.url;
            var id = infoObj.id;
            var appid = infoObj.appid;
            KgUser.CodeAll.appid = appid;
            var cssText = '.kg_sudoku_val_add b,.kg_sudoku_input_show span,.kg_sudoku_val_input a b{background:url(' + url + ') no-repeat  -500px -500px;} .kg_sudoku_input_show span{background-position:0 0;}';
            KgUser.LoadCss(cssText, 'kg_sudoku_style');
            var text = ['<div id="kg_sudoku_com" class="kg_sudoku_com">', '<div class="kg_sudoku_val_add kg_sudoku_clearfix" id="kg_sudoku_val_add">', '<b></b>', '<b></b>', '<b></b>', '<b></b>', '<b class="kg_sudoku_delete" title="清除" onclick="KgUser.DelSudokuCode(1);"></b>', '<div id="kg_sudoku_msg" class="kg_sudoku_msg"></div>', '</div>', '<div class="kg_sudoku_input_show"><span></span><a onclick="KgUser.ChangeSudokuCode(\'' + url + '\',1)">看不清,换一张?</a></div>', '<div class="kg_sudoku_ation">点击框内文字输入上图中对应<i>汉字</i></div>', '<div class="kg_sudoku_val_input kg_sudoku_clearfix" id="kg_sudoku_val_input">', '<a href="javascript:;"><b id="kg_sudoku_v_0"></b></a>', '<a href="javascript:;"><b id="kg_sudoku_v_1"></b></a>', '<a href="javascript:;"><b id="kg_sudoku_v_2"></b></a>', '<a href="javascript:;"><b id="kg_sudoku_v_3"></b></a>', '<a href="javascript:;"><b id="kg_sudoku_v_4"></b></a>', '<a href="javascript:;"><b id="kg_sudoku_v_5"></b></a>', '<a href="javascript:;"><b id="kg_sudoku_v_6"></b></a>', '<a href="javascript:;"><b id="kg_sudoku_v_7"></b></a>', '<a href="javascript:;"><b id="kg_sudoku_v_8"></b></a>', '</div>', '</div>'].join("");
            document.getElementById(id).innerHTML = text;
            var getStyle = function(id, prop) {
                var obj = document.getElementById(id);
                var ie = !+"\v1";
                var ie10 = document.documentMode;
                if (prop == "backgroundPosition") {
                    if (ie || ie10 == 10) {
                        return obj.currentStyle.backgroundPositionX + " " + obj.currentStyle.backgroundPositionY;
                    }
                }
                if (obj.currentStyle) {
                    return obj.currentStyle[prop];
                } else if (window.getComputedStyle) {
                    propprop = prop.replace(/([A-Z])/g, "-$1");
                    propprop = prop.toLowerCase();
                    return document.defaultView.getComputedStyle(obj, null)[prop];
                }
            }
            var kg_sudoku_addans = function(va, cval) {
                var kg_sudoku_anslist = KgUser.CodeAll.kg_sudoku_anslist;
                var kg_sudoku_flag = KgUser.CodeAll.kg_sudoku_flag;
                var adbs = document.getElementById("kg_sudoku_val_add").getElementsByTagName("b");
                for (var i = 0; i < kg_sudoku_anslist.length; i++) {
                    if (kg_sudoku_anslist[i] == "") {
                        kg_sudoku_anslist[i] = cval;
                        adbs[i].style.cssText = "background-position:" + va;
                        kg_sudoku_flag = i;
                        break;
                    }
                }
                if (kg_sudoku_flag == 3) {
                    KgUser.CodeAll.cval = kg_sudoku_anslist.join('');
                    setTimeout(function() {
                        KgUser.CheckCode({
                            appid: appid,
                            code: KgUser.CodeAll.cval,
                            type: 'RegCheckCode',
                            blurCallback: callbackName
                        }, "KgUser.CheckSudoCode");
                    }, 100);
                }
            }
            var kg_sudoku_addEvt = function(tab, ct, type) {
                var ctab = document.getElementById(tab).getElementsByTagName("b");
                for (var i = 0; i < ctab.length; i++) {
                    ctab[i].onclick = function std() {
                        c_val = parseInt(this.id.replace("kg_sudoku_v_", "")) + 1
                        var st = getStyle(this.id, "backgroundPosition");
                        var std = st.split(" ");
                        var st1, st2 = "";
                        if (!KgUser.IsEmpty(std[0])) {
                            st1 = parseInt(std[0].replace("px")) - 3;
                        }
                        if (!KgUser.IsEmpty(std[1])) {
                            st2 = parseInt(std[1].replace("px")) - 5;
                        }
                        kg_sudoku_addans(st1 + "px " + st2 + "px", c_val);
                    }
                }
            }
            kg_sudoku_addEvt("kg_sudoku_val_input");
        }
    },
    ChangeSudokuCode: function(url, clear) {
        setTimeout(function() {
            var cssText = '.kg_sudoku_val_add b,.kg_sudoku_input_show span,.kg_sudoku_val_input a b{background:url(' + url + '&nt=' + (new Date).getTime() + ') no-repeat -500px -500px;}  .kg_sudoku_input_show span{background-position:0 0;}';
            KgUser.LoadCss(cssText, 'kg_sudoku_style');
            KgUser.DelSudokuCode(clear);
        }, 200);
    },
    DelSudokuCode: function(clear) {
        KgUser.CodeAll.cval = "";
        KgUser.CodeAll.kg_sudoku_flag = 0;
        KgUser.CodeAll.kg_sudoku_anslist = ["", "", "", ""];
        var adbs = document.getElementById("kg_sudoku_val_add").getElementsByTagName("b");
        for (var i = 0; i < adbs.length; i++) {
            adbs[i].style.cssText = "";
        }
        if (clear == 1) {
            document.getElementById("kg_sudoku_msg").className = "kg_sudoku_msg";
        }
    },
    CheckSudoCode: function(infoObj) {
        var classname = "";
        if (!KgUser.IsEmpty(infoObj.errorCode)) {
            classname = "kg_sudoku_msg fail";
            document.getElementById("kg_sudoku_msg").className = classname;
            var url = KgUser.KgUrl.verify + "v1/get_img_code?type=RegCheckCode&appid=" + KgUser.CodeAll.appid + "&codetype=1&t=" + new Date().getTime();
            KgUser.ChangeSudokuCode(url, 0);
        } else {
            classname = "kg_sudoku_msg success";
            document.getElementById("kg_sudoku_msg").className = classname;
        }
    },
    CheckCode: function(infoObj, callbackName) {
        var appid = 0;
        var ct = parseInt(new Date().getTime() / 1000);
        var code = "";
        var cvalue = "";
        var type = "LoginCheckCode";
        var blurCallback = "";
        if (KgUser.IsEmpty(infoObj.appid)) {
            KgUser.GetMsg(callbackName, {
                errorCode: "20010",
                errorMsg: "必填参数不能为空"
            });
            return false;
        }
        if (!KgUser.IsEmpty(KgUser.Trim(infoObj.code))) {
            code = KgUser.Trim(infoObj.code);
            appid = infoObj.appid;
            if (!KgUser.IsEmpty(KgUser.Trim(infoObj.type))) {
                type = KgUser.Trim(infoObj.type);
            }
            if (!KgUser.IsEmpty(infoObj.blurCallback)) {
                blurCallback = infoObj.blurCallback;
            }
            var param = {
                'appid': appid,
                'ct': ct,
                'code': encodeURIComponent(code),
                'type': encodeURIComponent(type),
                'callback': callbackName
            };
            KgUser.loadScript(KgUser.KgUrl.loginHTTP + 'v1/check_img_code', param, blurCallback);
        }
    },
    Md5: function(str) {
        var hexcase = 0;
        var b64pad = "";
        var chrsz = 8;
        function hex_md5(s) {
            return binl2hex(core_md5(str2binl(s), s.length * chrsz));
        }
        function core_md5(x, len) {
            x[len >> 5] |= 0x80 << ((len) % 32);
            x[(((len + 64) >>> 9) << 4) + 14] = len;
            var a = 1732584193;
            var b = -271733879;
            var c = -1732584194;
            var d = 271733878;
            for (var i = 0; i < x.length; i += 16) {
                var olda = a;
                var oldb = b;
                var oldc = c;
                var oldd = d;
                a = md5_ff(a, b, c, d, x[i + 0], 7, -680876936);
                d = md5_ff(d, a, b, c, x[i + 1], 12, -389564586);
                c = md5_ff(c, d, a, b, x[i + 2], 17, 606105819);
                b = md5_ff(b, c, d, a, x[i + 3], 22, -1044525330);
                a = md5_ff(a, b, c, d, x[i + 4], 7, -176418897);
                d = md5_ff(d, a, b, c, x[i + 5], 12, 1200080426);
                c = md5_ff(c, d, a, b, x[i + 6], 17, -1473231341);
                b = md5_ff(b, c, d, a, x[i + 7], 22, -45705983);
                a = md5_ff(a, b, c, d, x[i + 8], 7, 1770035416);
                d = md5_ff(d, a, b, c, x[i + 9], 12, -1958414417);
                c = md5_ff(c, d, a, b, x[i + 10], 17, -42063);
                b = md5_ff(b, c, d, a, x[i + 11], 22, -1990404162);
                a = md5_ff(a, b, c, d, x[i + 12], 7, 1804603682);
                d = md5_ff(d, a, b, c, x[i + 13], 12, -40341101);
                c = md5_ff(c, d, a, b, x[i + 14], 17, -1502002290);
                b = md5_ff(b, c, d, a, x[i + 15], 22, 1236535329);
                a = md5_gg(a, b, c, d, x[i + 1], 5, -165796510);
                d = md5_gg(d, a, b, c, x[i + 6], 9, -1069501632);
                c = md5_gg(c, d, a, b, x[i + 11], 14, 643717713);
                b = md5_gg(b, c, d, a, x[i + 0], 20, -373897302);
                a = md5_gg(a, b, c, d, x[i + 5], 5, -701558691);
                d = md5_gg(d, a, b, c, x[i + 10], 9, 38016083);
                c = md5_gg(c, d, a, b, x[i + 15], 14, -660478335);
                b = md5_gg(b, c, d, a, x[i + 4], 20, -405537848);
                a = md5_gg(a, b, c, d, x[i + 9], 5, 568446438);
                d = md5_gg(d, a, b, c, x[i + 14], 9, -1019803690);
                c = md5_gg(c, d, a, b, x[i + 3], 14, -187363961);
                b = md5_gg(b, c, d, a, x[i + 8], 20, 1163531501);
                a = md5_gg(a, b, c, d, x[i + 13], 5, -1444681467);
                d = md5_gg(d, a, b, c, x[i + 2], 9, -51403784);
                c = md5_gg(c, d, a, b, x[i + 7], 14, 1735328473);
                b = md5_gg(b, c, d, a, x[i + 12], 20, -1926607734);
                a = md5_hh(a, b, c, d, x[i + 5], 4, -378558);
                d = md5_hh(d, a, b, c, x[i + 8], 11, -2022574463);
                c = md5_hh(c, d, a, b, x[i + 11], 16, 1839030562);
                b = md5_hh(b, c, d, a, x[i + 14], 23, -35309556);
                a = md5_hh(a, b, c, d, x[i + 1], 4, -1530992060);
                d = md5_hh(d, a, b, c, x[i + 4], 11, 1272893353);
                c = md5_hh(c, d, a, b, x[i + 7], 16, -155497632);
                b = md5_hh(b, c, d, a, x[i + 10], 23, -1094730640);
                a = md5_hh(a, b, c, d, x[i + 13], 4, 681279174);
                d = md5_hh(d, a, b, c, x[i + 0], 11, -358537222);
                c = md5_hh(c, d, a, b, x[i + 3], 16, -722521979);
                b = md5_hh(b, c, d, a, x[i + 6], 23, 76029189);
                a = md5_hh(a, b, c, d, x[i + 9], 4, -640364487);
                d = md5_hh(d, a, b, c, x[i + 12], 11, -421815835);
                c = md5_hh(c, d, a, b, x[i + 15], 16, 530742520);
                b = md5_hh(b, c, d, a, x[i + 2], 23, -995338651);
                a = md5_ii(a, b, c, d, x[i + 0], 6, -198630844);
                d = md5_ii(d, a, b, c, x[i + 7], 10, 1126891415);
                c = md5_ii(c, d, a, b, x[i + 14], 15, -1416354905);
                b = md5_ii(b, c, d, a, x[i + 5], 21, -57434055);
                a = md5_ii(a, b, c, d, x[i + 12], 6, 1700485571);
                d = md5_ii(d, a, b, c, x[i + 3], 10, -1894986606);
                c = md5_ii(c, d, a, b, x[i + 10], 15, -1051523);
                b = md5_ii(b, c, d, a, x[i + 1], 21, -2054922799);
                a = md5_ii(a, b, c, d, x[i + 8], 6, 1873313359);
                d = md5_ii(d, a, b, c, x[i + 15], 10, -30611744);
                c = md5_ii(c, d, a, b, x[i + 6], 15, -1560198380);
                b = md5_ii(b, c, d, a, x[i + 13], 21, 1309151649);
                a = md5_ii(a, b, c, d, x[i + 4], 6, -145523070);
                d = md5_ii(d, a, b, c, x[i + 11], 10, -1120210379);
                c = md5_ii(c, d, a, b, x[i + 2], 15, 718787259);
                b = md5_ii(b, c, d, a, x[i + 9], 21, -343485551);
                a = safe_add(a, olda);
                b = safe_add(b, oldb);
                c = safe_add(c, oldc);
                d = safe_add(d, oldd);
            }
            return Array(a, b, c, d);
        }
        function md5_cmn(q, a, b, x, s, t) {
            return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s), b);
        }
        function md5_ff(a, b, c, d, x, s, t) {
            return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
        }
        function md5_gg(a, b, c, d, x, s, t) {
            return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
        }
        function md5_hh(a, b, c, d, x, s, t) {
            return md5_cmn(b ^ c ^ d, a, b, x, s, t);
        }
        function md5_ii(a, b, c, d, x, s, t) {
            return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
        }
        function safe_add(x, y) {
            var lsw = (x & 0xFFFF) + (y & 0xFFFF);
            var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
            return (msw << 16) | (lsw & 0xFFFF);
        }
        function bit_rol(num, cnt) {
            return (num << cnt) | (num >>> (32 - cnt));
        }
        function str2binl(str) {
            var bin = Array();
            var mask = (1 << chrsz) - 1;
            for (var i = 0; i < str.length * chrsz; i += chrsz)
                bin[i >> 5] |= (str.charCodeAt(i / chrsz) & mask) << (i % 32);
            return bin;
        }
        function binl2hex(binarray) {
            var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
            var str = "";
            for (var i = 0; i < binarray.length * 4; i++) {
                str += hex_tab.charAt((binarray[i >> 2] >> ((i % 4) * 8 + 4)) & 0xF) + hex_tab.charAt((binarray[i >> 2] >> ((i % 4) * 8)) & 0xF);
            }
            return str;
        }
        str = str ? hex_md5(str) : '';
        return str;
    },
    Trim: function(str) {
        if (typeof str === "string") {
            return str.replace(/^\s+|\s+$/g, "");
        } else {
            return str;
        }
    },
    IsEmpty: function(obj) {
        if (typeof obj != 'undefined' && obj != null && obj != "") {
            return false;
        } else {
            return true;
        }
    },
    GetBytes: function() {
        var bytes = 0;
        for (var i = 0; i < this.length; i++) {
            if (this.charCodeAt(i) > 256) {
                bytes += 2;
            } else {
                bytes += 1;
            }
        }
        return bytes;
    },
    Intercept: function(length, appendStr) {
        var str = this;
        str = str.trim();
        if (str.getBytes() < length)
            return str;
        var countLen = 0;
        var charCount = 0;
        if (appendStr.length > 0) {
            length = length - appendStr.length;
        }
        for (var i = 0; i < str.length; i++) {
            if (this.charCodeAt(i) > 256) {
                countLen += 2;
            } else {
                countLen += 1;
            }
            if (countLen > length) {
                break;
            }
            charCount++;
        }
        return str.substr(0, charCount) + appendStr;
    },
    Guid: function() {
        function S4() {
            return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
        }
        return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
    },
    CheckAutoLogin: function() {
        var kugouid = KgUser.Cookie.read('KuGoo', 'KugooID');
        var clienttime = KgUser.Cookie.read('KuGoo', 'ct');
        var now = parseInt(new Date().getTime() / 1000);
        if (now - clienttime > 86400) {
            KgUser.AutoLogin('');
        }
    }
};




var m_val = KgUser.Cookie.read(KgUser.KgMid.name);
if (KgUser.IsEmpty(m_val)) {
    var n = KgUser.Guid();
    KgUser.Cookie.write(KgUser.KgMid.name, KgUser.Md5(n), KgUser.KgMid.days * 86400, "/", KgUser.GetDomain());
}
if ("kugou.com" != KgUser.GetDomain()) {
    KgUser.CrossDomainLogin('');
} else {
    KgUser.CheckAutoLogin();
}
try {
    document.execCommand('BackgroundImageCache', false, true);
} catch (e) {}
;KgUser.loadAckJs();
